package pers.kw.config.mq;

import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import pers.kw.contants.RabbitMQContants;

/**
 * 声明：交换机、队列、及其绑定关系
 */
@Configuration
public class RabbitMQConfig {

    /**
     * 声明交换机
     */
    @Bean
    public Exchange znxExchange() {
        return ExchangeBuilder.fanoutExchange(RabbitMQContants.ZNX_EXCHANGE).build();
    }

    /**
     * 声明队列
     */
    @Bean
    public Queue znxQueue() {
        return QueueBuilder.durable(RabbitMQContants.ZNX_QUEUE).build();
    }

    /**
     * 队列绑定交换机
     */
    @Bean
    public Binding znxBinding(Exchange znxExchange, Queue znxQueue) {
        return BindingBuilder.bind(znxQueue).to(znxExchange).with("").noargs();
    }
}
